

package com.ccblife.third.msagent.msagentfeign.rpc;


import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class MsagentClientFactoryBean<T> implements FactoryBean<T> {

   private Class<T> interfaceType;
     public MsagentClientFactoryBean(Class<T> interfaceType) {
      this.interfaceType = interfaceType;
      }

	@Override
	public T getObject() throws Exception {
		InvocationHandler handler = new DefaultInvocationHandler<>(interfaceType);
		return (T) Proxy.newProxyInstance(interfaceType.getClassLoader(),
				new Class[] {interfaceType},handler);
	}

	@Override
	public Class<?> getObjectType() {
		return interfaceType;
	}

	@Override
	public boolean isSingleton() {
		return true;
	}


}
